package gentlesik;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HelloJDBC {
	public static void main(String[] args) {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
		DataSource bean = (DataSource) context.getBean("DataSource");
		System.out.println(bean);
		
		try {
			Connection c = bean.getConnection();
			PreparedStatement p = c.prepareStatement("select * from products");
			ResultSet r = p.executeQuery();
			
			String name = null;
			while (r.next()) {
				name = r.getString("name");
				System.out.println(name);
			}
			
			r.close();
			p.close();
			c.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
